/*
 *  MilovoCommonFuncs.h
 *  Milovo04alfa00
 *
 *  Created by Luca on 21/11/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef MILOVOCOMMONFUNCS_H
#define MILOVOCOMMONFUNCS_H

#include "Milovo.h"
#include "Milovo_HCommons.h"
#include "SimulationParam.h"
#include "InitParam.h"
#include "SystemParam.h"

// Functions in MilovoCommonFuncs.cpp file
Mil_Int CalcOutputThisRecipe(list<Mil_Int> &, list<Mil_Int> &, Artifacts *, int);
Mil_Int DoCalc(Mil_Int , Mil_Int , Mil_Int);
Mil_Int ValidateThisOutputRecipe(Mil_Int, Mil_Int, vector<Mil_Int> &, Mil_Int, Mil_Int, Agents *, Mil_Int, MilinitParams &, int);
void CheckOutputThisAgentToCompare(vector<Mil_Int> &, MilinitParams &, vector<Mil_Int> &, Agents *, Recipes *, Artifacts *, int);

void GetAgentsAlive(vector<Mil_Int> &, Agents *, int);

void GenerateRelationshipThisAgent(Mil_Int , Agents *, Recipes *, Artifacts *, int, int);
void ExtractIDAgentsKnowedByThisAgent(Mil_Int , Agents *, Recipes *, Artifacts *, int, int);
void ExtractCurrentFriendsThisAgent(vector<Mil_Int> &, Mil_Int , Agents *, Recipes *, Artifacts *, int);
void AddNewFriendsThisAgent(vector<Mil_Int> &, Mil_Int , Agents *, Recipes *, Artifacts *, int);
void DeleteOldFriendsThisAgents(vector<Mil_Int> &, Mil_Int , Agents *, Recipes *, Artifacts *, int, int);
void ExtractIDArtifactsFromRelationshipsThisAgent(Mil_Int , Agents *, Recipes *, Artifacts *, int);
bool AddScaffoldingFriends(Mil_Int tmpIDAgentToAnalize, Agents *, ScaffoldingStructure *, int);
void SubscribeThisAgent(Mil_Int , ScaffoldingStructure *, Mil_Int, MilovoRandom &, int);
void InitScaffoldingStructure(Agents *, ScaffoldingStructure *, SystemParams &, int);
Mil_Int GetHowManyCopyThisArtifactInRecipe(Mil_Int , Artifacts *, Mil_Int, Recipes *, int);

void CalcVotesThisAgent(Mil_Int , Agents *, SystemParams &, int);
Mil_Double CalcSigmaFunction(Mil_Double, SystemParams &, int);
void SetProjectTheseAgents(vector<Mil_Int> &, Agents *, bool , int);


vector<Mil_Int> ExtractVectIDArtifactsAvailableThisAgent(Mil_Int , Artifacts *, int);
void ExtractVectIDArtifactsKnowedByThisAgent(vector<Mil_Int> &, Mil_Int , Agents *, Recipes *, Artifacts *, int);
void ExtractListOutputThisAgent(list<Mil_Int> &, Mil_Int , Agents *, Recipes *, Artifacts *, int);
Mil_Int FindArtifactSubstitute(Artifacts *, Agents *, Recipes *, Mil_Int, Mil_Int , Mil_Int , Mil_Int , Mil_Int , MilovoRandom &, int);
Mil_Int FindArtifactSubstitutePreferential(Artifacts *, Agents *, Recipes *, Mil_Int, Mil_Int , Mil_Int , Mil_Int , Mil_Int , int);

void KillThisRecipe(Mil_Int , Recipes *, Artifacts *, Agents *, int);
void KillThisAgent(Mil_Int CurrentIDAgent, Agents *CurrentTabAgents, Recipes *CurrentTabRecipes, Artifacts *CurrentTabArtifacts, int CurrentDebugLevel);

void InsertNewRecipe(MilinitParams &, SystemParams &, MilovoRandom &, Agents *, Mil_Int , Recipes *, Artifacts *, 
							list<Mil_Int> &, list<Mil_Int> &, Mil_Int , Mil_Int , Mil_Int, int);

void DeleteRecipesWithLessArtifactsStatus(Mil_Int , Agents *, Recipes *, Artifacts *, int);

void ExtractIDArtifactsBornThisStep(vector<Mil_Int> &, Artifacts *, Mil_Int , Agents *, int , int);
void ExtractIDAgentOwnerArtifactsBornThisStep(vector<Mil_Int> &, vector<Mil_Int> &, Artifacts *, int);

Mil_Int AdjustOutputOnBoundary(Mil_Int tmpRecipeOutputName, Mil_Int tmpLowBoundary, Mil_Int tmpHighBoundary);
Mil_Int CheckOutputCopiesThisAgent(Mil_Int tmpRecipeOutputName, vector<Mil_Int> &tmpValueToCompare);
Mil_Int CheckOutputEqualRawMaterials(Mil_Int tmpRecipeOutputName, MilinitParams &tmp_Current_Init_Param);
Mil_Int CheckOutputIntoGoalRange(Mil_Int tmpRecipeOutputName, Mil_Int tmp_GoalToCompare);
Mil_Int InvalidateOutputOnBoundary(Mil_Int tmpRecipeOutputName, Mil_Int tmpLowBoundary, Mil_Int tmpHighBoundary);
Mil_Int AdjustOutputOnTorus(Mil_Int tmpRecipeOutputName, Mil_Int tmpHighBoundary, Mil_Int tmpLowBoundary);

#endif

